package nancal.mp

import nancal.mp.db.redis.rer
import nbcp.base.event.GetLoginUserEvent
import nbcp.base.extend.FromJson
import nbcp.mvc.HttpContext
import org.slf4j.LoggerFactory
import org.springframework.context.event.EventListener

//@Configuration
class BusinessInit {
    companion object {
        private val logger = LoggerFactory.getLogger(this::class.java.declaringClass)
    }

    @EventListener
    fun getLoginUser(ev: GetLoginUserEvent) {
        if (!HttpContext.hasRequest) {
            return;
        }
        var token = HttpContext.token
        if (token.isNullOrEmpty()) {
            return;
        }


        var user = rer.sys.token(token).get();
        if (user.isNullOrEmpty()) {
            return;
        }

        ev.result = user.FromJson()
    }

}